<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=0">

	<title>地址管理</title>

	<link href="/static/home/AmazeUI-2.4.2/assets/css/admin.css" rel="stylesheet" type="text/css">
	<link href="/static/home/AmazeUI-2.4.2/assets/css/amazeui.css" rel="stylesheet" type="text/css">

	<link href="/static/home/css/personal.css" rel="stylesheet" type="text/css">
	<link href="/static/home/css/addstyle.css" rel="stylesheet" type="text/css">
	<script src="/static/home/AmazeUI-2.4.2/assets/js/jquery.min.js" type="text/javascript"></script>
	<script src="/static/home/AmazeUI-2.4.2/assets/js/amazeui.js"></script>

</head>

<body>
<!--头 -->
<header>
	<article>
		<div class="mt-logo">
			<!--顶部导航条 -->
			<div class="am-container header">
				<ul class="message-l">
					<!--<div class="topMessage">
						<div class="menu-hd">
							<a href="#" target="_top" class="h">亲，请登录</a>
							<a href="#" target="_top">免费注册</a>
						</div>
					</div>-->
				</ul>
				<ul class="message-r">
					<div class="topMessage home">
						<div class="menu-hd"><a href="/index/index/index/" target="_top" class="h">商城首页</a></div>
					</div>
					<div class="topMessage my-shangcheng">
						<div class="menu-hd MyShangcheng"><a href="/index/person/index" target="_top"><i
							class="am-icon-user am-icon-fw"></i>个人中心</a></div>
					</div>
					<div class="topMessage mini-cart">
						<div class="menu-hd"><a id="mc-menu-hd" href="/index/person/shopcart" target="_top"><i
							class="am-icon-shopping-cart  am-icon-fw"></i><span>购物车</span><strong id="J_MiniCartNum"
																								  class="h"></strong></a>
						</div>
					</div>
					<div class="topMessage favorite">
						<div class="menu-hd"><a href="#" target="_top"><i
							class="am-icon-heart am-icon-fw"></i><span>收藏夹</span></a></div>

					</div>
					<a href="/index/index/loginout" style="float: right; margin-top: 8px"> 退出</a>

				</ul>
			</div>

			<!--悬浮搜索框-->

			<div class="nav white">
				<div class="logoBig">
					<li><img src="/static/home/images/logobig.png"/></li>
				</div>

				<div class="search-bar pr">
					<a name="index_none_header_sysc" href="#"></a>
					<form>
						<input id="searchInput" name="index_none_header_sysc" type="text" placeholder="搜索"
							   autocomplete="off">
						<input id="ai-topsearch" class="submit am-btn" value="搜索" index="1" type="submit">
					</form>
				</div>
			</div>

			<div class="clear"></div>
		</div>
		</div>
	</article>
</header>

<!--<div class="nav-table">
	<div class="long-title"><span class="all-goods">全部分类</span></div>
	<div class="nav-cont">
		<ul>
			<li class="index"><a href="#">首页</a></li>
			<li class="qc"><a href="#">闪购</a></li>
			<li class="qc"><a href="#">限时抢</a></li>
			<li class="qc"><a href="#">团购</a></li>
			<li class="qc last"><a href="#">大包装</a></li>
		</ul>
		<div class="nav-extra">
			<i class="am-icon-user-secret am-icon-md nav-user"></i><b></b>我的福利
			<i class="am-icon-angle-right" style="padding-left: 10px;"></i>
		</div>
	</div>
</div>-->
<b class="line"></b>

<div class="center">
	<div class="col-main">
		<div class="main-wrap">

			<div class="user-address">
				<!--标题 -->
				{if isset($receiveAddress)}

				<div class="am-cf am-padding">
					<div class="am-fl am-cf"><strong class="am-text-danger am-text-lg">地址管理</strong> /
						<small>Address&nbsp;list</small>
					</div>
				</div>
				<hr/>
				<ul class="am-avg-sm-1 am-avg-md-3 am-thumbnails">
					{foreach $receiveAddress as $val}
					{if $val['is_default'] == 1}
					<!---------------------------------------------------------------->
					<li class="user-addresslist defaultAddr">
						<span class="new-option-r"><i class="am-icon-check-circle" value='good'
													  id="good"></i>默认地址</span>
						<p class="new-tit new-p-re">
							<span class="new-txt">{$val['receive_name']}</span>
							<span class="new-txt-rd2" id="">{$val['receive_phone']|substr=0,3}****{$val['receive_phone']|substr=7}</span>
						</p>
						<div class="new-mu_l2a new-p-re">
							<p class="new-mu_l2cw">
								<span class="title">地址：{$val['receive_address']}</span>
								<span class="street">{$val['detail_address']}</span>
							</p>
						</div>
						<div class="new-addr-btn">
							<a href="#" id="default">
								<input type="hidden" value="{$val['receive_id']}">
								<i class="am-icon-trash"></i>
								删除
							</a>
						</div>
					</li>
					{/if}
					{/foreach}
					<!------------------------------------------------------------------>
					{foreach $receiveAddress as $val}
					{if $val['is_default'] == 0}
					<li class="user-addresslist">
						<a class="new-option-r"
						   href="/index/person/Adddefault?aid={$val['receive_id']}&uid={$val['uid']}"><i
							class="am-icon-check-circle"></i>设为默认</a>
						<p class="new-tit new-p-re">
							<span class="new-txt">{$val['receive_name']}</span>
							<span class="new-txt-rd2">{$val['receive_phone']|substr=0,3}****{$val['receive_phone']|substr=7}</span>
						</p>
						<div class="new-mu_l2a new-p-re">
							<p class="new-mu_l2cw">
								<span class="title">地址：{$val['receive_address']}</span>
								<!--<span class="province">湖北</span>省
								<span class="city">武汉</span>市
								<span class="dist">洪山</span>区-->
								<span class="street">{$val['detail_address']}</span></p>
						</div>
						<div class="new-addr-btn">
							<!--<a href="#"><i class="am-icon-edit"></i>编辑</a>
							<span class="new-addr-bar">|</span>-->
							<a href="/index/person/delAdd?id={$val['receive_id']}"><i class="am-icon-trash"></i>删除</a>
						</div>
					</li>
					{/if}
					{/foreach}
					<!------------------------------------------------------------>

				</ul>
				{/if}

				<div class="clear"></div>
				<a class="new-abtn-type" data-am-modal="{target: '#doc-modal-1', closeViaDimmer: 0}">添加新地址</a>
				<!--例子-->
				<div class="am-modal am-modal-no-btn" id="doc-modal-1">

					<div class="add-dress">

						<!--标题 -->
						<div class="am-cf am-padding">
							<div class="am-fl am-cf"><strong class="am-text-danger am-text-lg">新增地址</strong> /
								<small>Add&nbsp;address</small>
							</div>
						</div>
						<hr/>

						<div class="am-u-md-12 am-u-lg-8" style="margin-top: 20px;">
							<form class="am-form am-form-horizontal">

								<div class="am-form-group">
									<label for="user-name" class="am-form-label">收货人</label>
									<div class="am-form-content">
										<input type="text" id="user-name" placeholder="收货人">
										<span id="user-nameTip"></span>
									</div>
								</div>

								<div class="am-form-group">
									<label for="user-phone" class="am-form-label">手机号码</label>
									<div class="am-form-content">
										<input id="user-phone" placeholder="手机号必填" type="email">
										<span id="user-phoneTip"></span>
									</div>
								</div>
								<div class="am-form-group">
									<label for="" class="am-form-label">所在地</label>
									<div class="am-form-content address">
										<select data-am-selected id="privince">
											<option value="请选择">请选择</option>
											{foreach $area0 as $val}
											<option value="{$val['area_id']}">{$val['area_name']}</option>
											{/foreach}
										</select>
										<select data-am-selected id="city">
										</select>
										<select data-am-selected id="country">
											<option></option>
										</select>
									</div>
								</div>

								<div class="am-form-group">
									<label for="user-intro" class="am-form-label">详细地址</label>
									<div class="am-form-content">
										<textarea class="" rows="3" id="user-intro" placeholder="输入详细地址"></textarea>
										<small>100字以内写出你的详细地址...</small>
										<span id="user-introTip"></span>
									</div>
								</div>

								<div class="am-form-group">
									<div class="am-u-sm-9 am-u-sm-push-3">
										<a class="am-btn am-btn-danger" id="user-submit">保存</a>
										<a id="user-cancle" class="am-close am-btn am-btn-danger"
										   data-am-modal-close>取消</a>
									</div>
								</div>
							</form>
						</div>

					</div>

				</div>

			</div>

			<script type="text/javascript">
                $(document).ready(function () {
                    $(".new-option-r").click(function () {
                        $(this).parent('.user-addresslist').addClass("defaultAddr").siblings().removeClass("defaultAddr");
                    });

                    var $ww = $(window).width();
                    if ($ww > 640) {
                        $("#doc-modal-1").removeClass("am-modal am-modal-no-btn")
                    }

                })
			</script>

			<div class="clear"></div>

		</div>
		<!--底部-->
		<div class="footer">
			<div class="footer-hd">
				<p>
					<a href="#">恒望科技</a>
					<b>|</b>
					<a href="/index/index/index">商城首页</a>
					<b>|</b>
					<a href="#">支付宝</a>
					<b>|</b>
					<a href="#">物流</a>
				</p>
			</div>
			<div class="footer-bd">
				<p>
					<a href="#">关于恒望</a>
					<a href="#">合作伙伴</a>
					<a href="#">联系我们</a>
					<a href="#">网站地图</a>
					<em>© 2015-2025 Hengwang.com 版权所有</em>
				</p>
			</div>
		</div>
	</div>

	<aside class="menu">
		<ul>
			<li class="person active">
				<a href="/index/person/index"><i class="am-icon-user"></i>个人中心</a>
			</li>
			<li class="person">
				<p><i class="am-icon-newspaper-o"></i>个人资料</p>
				<ul>
					<li><a href="/index/person/information">个人信息</a></li>
					<li><a href="/index/person/password">安全设置</a></li>
					<li><a href="/index/person/address">地址管理</a></li>
					<li><a href="#">快捷支付</a></li>
				</ul>
			</li>
			<li class="person">
				<p><i class="am-icon-balance-scale"></i>我的交易</p>
				<ul>
					<li><a href="/index/person/order">订单管理</a></li>
					<li><a href="#">退款售后</a></li>
					<li><a href="#">评价商品</a></li>
				</ul>
			</li>
			<li class="person">
				<p><i class="am-icon-dollar"></i>我的资产</p>
				<ul>
					<li><a href="#">我的积分</a></li>
					<li><a href="#">优惠券 </a></li>
					<li><a href="#">红包</a></li>
					<li><a href="#">账户余额</a></li>
					<li><a href="#">账单明细</a></li>
				</ul>
			</li>

			<li class="person">
				<p><i class="am-icon-tags"></i>我的收藏</p>
				<ul>
					<li><a href="#">收藏</a></li>
					<li><a href="#">足迹</a></li>
				</ul>
			</li>

			<li class="person">
				<p><i class="am-icon-qq"></i>在线客服</p>
				<ul>
					<li><a href="#">商品咨询</a></li>
					<li><a href="#">意见反馈</a></li>

					<li><a href="#">我的消息</a></li>
				</ul>
			</li>
		</ul>

	</aside>
</div>
</body>
<script>
    $(function () {
        //根据省得到市-------------------------------------------------
        $('#privince').change(function () {
            if ($('#privince').val() == '请选择') {
                console.log($('#privince').val());
                $('#city').find('option').remove();
                $('#country').find('option').remove();
            }
            $.post('city', {privince: $('#privince').val()}, success, 'json');
        });
        //根据市得到县
        $('#city').change(function () {
            $.post('country', {country: $('#city').val()}, success, 'json');
        });
        //得到省市县
        var addressFlag = false;

        var addressId = null;
        $('#country').change(function () {
            var privinceId = $('#privince').val();
            var cityId = $('#city').val();
            var countryId = $('#country').val();
            addressFlag = true;
            addressId = '_' + privinceId + '_' + cityId + '_' + countryId + '_';
        });

        //得到收货人地址-----------------------------------------
        var userFlag = false;	//是否填写收件人

        var username = null;
        $('#user-name').blur(function () {
            username = $('#user-name').val();
            if (username.length > 1) {
                $('#user-nameTip').text('用户名可用').css('color', 'blue');
                userFlag = true;
            } else {
                $('#user-nameTip').text('用户名有误').css('color', 'red');
                userFlag = false;
            }
        });
        $('#user-name').focus(function () {
            $('#user-nameTip').text('');
        });

        //获取手机号-------------------------------------------------
        var phoneFlag = false;

        var phone = null;
        var reg = /^[1][3,4,5,7,8][0-9]{9}$/;
        $('#user-phone').blur(function () {
            phone = $('#user-phone').val();
            if ((phone.length == 11) && (parseInt(phone) == phone) && reg.test(phone)) {
                $('#user-phoneTip').text('号码正确').css('color', 'blue');
                phoneFlag = true;
            } else {
                $('#user-phoneTip').text('号码有误').css('color', 'red');
                phoneFlag = false;
            }
        });
        $('#user-phone').focus(function () {
            $('#user-phoneTip').text('');
        });

        //获取详细地址---------------------------------------------
        var introFlag = false;

        var intro = null;
        $('#user-intro').blur(function () {
            intro = $('#user-intro').val();
            if (intro.length == 0) {
                $('#user-introTip').text('请填写详细信息').css('color', 'red');
                introFlag = false;
            } else {
                introFlag = true;
            }
        });
        $('#user-intro').focus(function () {
            $('#user-introTip').text('');
        });

        //提交文件-------------------------------------------------
        $('#user-submit').mousedown(function () {
            setTimeout(function () {
                if (userFlag && phoneFlag && addressFlag && introFlag) {
                    $.post('addressInsert', {
                        user: username,
                        phone: phone,
                        detailId: addressId,
                        detailAdd: intro
                    }, success, 'json');
                }
            }, 600);
        });

        //取消事件
        $('#user-cancle').mousedown(function () {
            window.location.href = '/index/person/address';
        });

        function success(data) {
            switch (data.value) {
                case 1:
                    area1 = data.area1;
                    area2 = data.area2;
                    break;
                case 2:
                    city = data.city;
                    $('#city').find('option').remove();
                    $.each(city, function () {
                        $('#city').append("<option value = '" + this.area_id + "'>" + this.area_name + "</option>");
                    });
                    break;
                case 3:
                    country = data.country;
                    $('#country').find('option').remove();
                    $.each(country, function () {
                        $('#country').append("<option value = '" + this.area_id + "'>" + this.area_name + "</option>");
                    });
                    break;
                case 4:
                    alert('收货地址保存成功');
                    userFlag = false;
                    window.location.href = '/index/person/address';
                    break;
                case 5:
                    alert('地址添加失败, 请重试');
                    userFlag = false;
                    break;
            }
        }


        //删除收件地址
        $('#default').click(function () {
            $delId = $('#default').children(":first").val();
            $.post('delAddress', {id: $delId}, doIt, 'json');
        });

        //返回修改信息
        function doIt(value) {
            switch (value.state) {
                case 1:
                    alert('删除成功');
                    window.location.href = '/index/person/address';
                    break;
                case 2:
                    alert('删除失败');
                    break;
            }
        }
    });
</script>
</html>